﻿package plugin.union.game
{
    import cmd.*;
    import com.core.*;
    import com.greensock.*;
    import flash.display.*;
    import manager.*;
    import morn.core.handlers.*;
    import plugin.component.*;
    import plugin.union.*;
    import uiresource.union.*;

    public class UnionGame extends UnionUI
    {
        private var _instance:Union;
        private var _tabArr:Array;
        private var _curView:IPage;
        public var _reTime:Array;
        private var _timeline:TimelineLite;

        public function UnionGame(param1:Union)
        {
            this._tabArr = [UnionListGame, UnionInfoGame, UnionSalaryGame, UnionActivityGame, UnionCkGame, UnionHongBaoGame, UnionTotemGame];
            this._reTime = [];
            this._instance = param1;
            return;
        }// end function

        override protected function initializeView() : void
        {
            var _loc_1:* = Control.create(UnionControl, this);
            ModelProxy.addObserver("union", _loc_1);
            XMLMcManager.instance.complatefuncs["union"] = this.mcComplate;
            this.initEvent();
            return;
        }// end function

        private function mcComplate() : void
        {
            if (this._curView is UnionHongBaoGame)
            {
                (this._curView as UnionHongBaoGame).refresh();
            }
            return;
        }// end function

        public function showPage(param1:int) : void
        {
            var _loc_3:IPage = null;
            var _loc_2:* = this._tabArr[param1];
            if (_loc_2)
            {
                if (_loc_2 is Class)
                {
                    if (this.checkRefreshTime(param1))
                    {
                        return;
                    }
                    _loc_3 = new _loc_2;
                    if (this._curView)
                    {
                        (this._curView as DisplayObject).visible = false;
                    }
                    this._curView = _loc_3;
                    this.addChild(_loc_3 as DisplayObject);
                    this._tabArr[tab_title.selectedIndex] = _loc_3;
                    _loc_3.refresh();
                }
                else if (_loc_2 is String)
                {
                    if (_loc_2 == "store")
                    {
                        ModelProxy.change("plugin", "open", {target:_loc_2, data:4});
                    }
                    ModelProxy.change("movetips", "error", "功能开发中");
                }
                else
                {
                    if (this.checkRefreshTime(param1))
                    {
                        return;
                    }
                    if (this._curView)
                    {
                        (this._curView as DisplayObject).visible = false;
                    }
                    _loc_2.visible = true;
                    this._curView = _loc_2;
                    _loc_2.refresh();
                }
            }
            return;
        }// end function

        public function checkRefreshTime(param1:int) : Boolean
        {
            var _loc_2:Number = NaN;
            var _loc_3:int = 0;
            switch(param1)
            {
                case 0:
                {
                    _loc_2 = new Date().getTime();
                    if (!this._reTime[param1] || _loc_2 - this._reTime[param1] > 5000)
                    {
                        this._reTime[param1] = _loc_2;
                        UnionSender._2getUnionList();
                        return true;
                    }
                    break;
                }
                case 1:
                {
                    _loc_2 = new Date().getTime();
                    _loc_3 = UserData.getUserData("unionid");
                    if (!this._reTime[param1] || _loc_2 - this._reTime[param1] > 5000)
                    {
                        this._reTime[param1] = _loc_2;
                        UnionSender._4getUnionInfo(_loc_3);
                        return true;
                    }
                    break;
                }
                case 2:
                {
                    _loc_2 = new Date().getTime();
                    if (!this._reTime[param1] || _loc_2 - this._reTime[param1] > 10000)
                    {
                        this._reTime[param1] = _loc_2;
                        UnionSender._26getSalaryInfo();
                        return true;
                    }
                    break;
                }
                case 6:
                {
                    _loc_2 = new Date().getTime();
                    if (!this._reTime[param1] || _loc_2 - this._reTime[param1] > 600000)
                    {
                        this._reTime[param1] = _loc_2;
                        UnionSender._31getTotem();
                        return true;
                    }
                    break;
                }
                case 4:
                {
                    _loc_2 = new Date().getTime();
                    if (!this._reTime[param1] || _loc_2 - this._reTime[param1] > 600000)
                    {
                        this._reTime[param1] = _loc_2;
                        UnionSender._50getCkInfo();
                        return true;
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return false;
        }// end function

        private function initEvent() : void
        {
            btn_close.clickHandler = new Handler(this._instance.close);
            tab_title.selectHandler = new Handler(this.showPage);
            return;
        }// end function

        public function update(param1:int, param2:Object) : void
        {
            var _loc_3:int = 0;
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            var _loc_6:Object = null;
            var _loc_7:Object = null;
            switch(param1)
            {
                case CMDUnion._3GETUNIONLIST:
                {
                    _loc_3 = UserData.getUserData("unionid");
                    if (_loc_3 == 0)
                    {
                        tab_title.labels = "行会列表";
                        for (_loc_5 in this._reTime)
                        {
                            
                            if (_loc_5 != 0)
                            {
                                this._reTime[_loc_5] = 0;
                            }
                        }
                    }
                    else
                    {
                        _loc_6 = ModelProxy.getValue("data", "unionsInfo");
                        for each (_loc_7 in _loc_6)
                        {
                            
                            if (_loc_7.unionId == _loc_3)
                            {
                                if (_loc_7.unionLevel >= 20)
                                {
                                    tab_title.labels = "行会列表,行会信息,行会福利,行会活动,行会仓库,行会红包,行会图腾";
                                }
                                else
                                {
                                    tab_title.labels = "行会列表,行会信息,行会福利,行会活动,行会仓库,行会红包";
                                }
                                break;
                            }
                        }
                    }
                    tab_title.selectedIndex = 0;
                    this.showPage(0);
                    break;
                }
                case CMDUnion._5GETUNIONINFO:
                {
                    _loc_4 = ModelProxy.getValue("data", "unionInfo");
                    if (_loc_4.unionLevel >= 20)
                    {
                        tab_title.labels = "行会列表,行会信息,行会福利,行会活动,行会仓库,行会红包,行会图腾";
                    }
                    else
                    {
                        tab_title.labels = "行会列表,行会信息,行会福利,行会活动,行会仓库,行会红包";
                    }
                    tab_title.selectedIndex = 1;
                    this.showPage(1);
                    break;
                }
                case CMDUnion._27GETSALARYINFO:
                {
                    tab_title.selectedIndex = 2;
                    this.showPage(2);
                    break;
                }
                case CMDUnion._42REFER:
                {
                    if (tab_title.selectedIndex == 1 || tab_title.selectedIndex == 6 || tab_title.selectedIndex == 4)
                    {
                        this._curView.refresh();
                    }
                    break;
                }
                case CMDUnion._32GETTOTEM:
                {
                    tab_title.selectedIndex = 6;
                    this.showPage(6);
                    break;
                }
                case CMDUnion._34UPTOTEM:
                {
                    if (tab_title.selectedIndex == 6)
                    {
                        this._curView.refresh();
                    }
                    break;
                }
                case CMDUnion._46CHANGEPOSITION:
                case CMDUnion._22MEMBERLEAVE:
                {
                    if (this.visible)
                    {
                        if (tab_title.selectedIndex == 1)
                        {
                            this._curView.refresh();
                        }
                    }
                    break;
                }
                case CMDUnion._51GETCKINFO:
                {
                    tab_title.selectedIndex = 4;
                    this.showPage(4);
                    break;
                }
                case CMDUnion._55TOGETCK:
                {
                    if (tab_title.selectedIndex == 4)
                    {
                        this._curView.update(CMDUnion._55TOGETCK, null);
                    }
                    break;
                }
                case UnionPublics.UPDATECONTRIBUTION:
                {
                    if (this._curView == null)
                    {
                        return;
                    }
                    if (tab_title.selectedIndex == 6 || tab_title.selectedIndex == 4)
                    {
                        this._curView.update(UnionPublics.UPDATECONTRIBUTION, null);
                    }
                    break;
                }
                case UnionPublics.UPDATEBAG:
                {
                    if (this._curView == null)
                    {
                        return;
                    }
                    if (this.visible)
                    {
                        this._curView.update(UnionPublics.UPDATEBAG, null);
                    }
                    break;
                }
                case UnionPublics.TODONATE:
                {
                    tab_title.selectedIndex = 4;
                    this.showPage(4);
                    break;
                }
                case CMDUnion._56UNIONBOSSOPEN:
                {
                    if (tab_title.selectedIndex == 3)
                    {
                        this._curView.update(CMDUnion._56UNIONBOSSOPEN, null);
                    }
                    break;
                }
                case CMDUnion._59UNIONEMSSTATE:
                {
                    if (tab_title.selectedIndex == 3)
                    {
                        this._curView.update(CMDUnion._59UNIONEMSSTATE, param2);
                    }
                    break;
                }
                case CMDUnion._67ResRedPacketInfo:
                {
                    if (tab_title.selectedIndex == 5)
                    {
                        this._curView.update(CMDUnion._67ResRedPacketInfo, param2);
                    }
                    break;
                }
                case CMDUnion._70ResGetRedPacket:
                {
                    if (tab_title.selectedIndex == 5)
                    {
                        this._curView.update(CMDUnion._70ResGetRedPacket, param2);
                    }
                    break;
                }
                case UnionPublics.GETDEBUG:
                {
                    this._curView.update(UnionPublics.GETDEBUG, null);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

    }
}
